package com.iptv.grape;

import android.content.Intent;

import com.iptv.grape.domain.UserInfo;
import com.iptv.grape.net.Entity.LoginData;
import com.iptv.grape.net.Entity.LoginResult;
import com.iptv.grape.net.NetworkService;
import com.iptv.grape.util.AppLog;
import com.iptv.grape.util.SharedUtil;

public class StartAct extends BaseAct implements NetworkService.OkCall {
    @Override
    protected int layout() {
        return 0;
    }

    @Override
    protected void initView() {
        boolean isFirst = SharedUtil.getSp(SharedUtil.FILE_DEFUALT).getBoolean("isFirst", true);
        NetworkService.getInstance().login(this);


    }


    @Override
    public void error(int code, String msg) {
        switch (code) {
            case -1:

                break;
            case 0:

                break;
        }

    }

    @Override
    public void success(String value) {
        LoginResult result = LoginResult.CreateForJson(value);
        if (null == result) {
            return;
        }
        if (result.getRtCode().equals("S")) {
            LoginData data = result.getData();
            if (data != null) {
                SharedUtil.put(SharedUtil.FILE_DEFUALT,"isFirst", false);
                UserInfo.setUserInfo(data);
                Intent intent = new Intent();
                intent.setClass(StartAct.this,MainActivity.class);
                AppLog.getCurLog().out("startMainActivity");
                startActivity(intent);
            }else{
                UserInfo userInfo = UserInfo.unSerializeToFile();
            }

        } else {
        }

    }
}
